package bh

import android.content.Intent
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import yyee.llee.mmee.common.databinding.ActivityWeatherSettingBinding
import yyee.llee.mmee.common.global.Env
import yyee.llee.mmee.weather.adapter.SettingAdapter

class GB : Fragment() {


    private var bind: ActivityWeatherSettingBinding? = null
    private val viewBinding get() = bind!!
    private lateinit var mAdapter: SettingAdapter


    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?,
    ): View? {
        bind = ActivityWeatherSettingBinding.inflate(inflater)
        return bind?.root
    }


    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        initView()
        initData()
    }


    companion object {

        private var instance: GB? = null
        fun getInstance(): GB {
            if (instance == null) {
                instance = GB()
            }
            return instance!!
        }
    }

    private fun initView() {

    }


    private fun initData() {
        val titles = arrayOf("用户协议", "隐私政策", "关于我们")
        mAdapter = SettingAdapter(requireActivity(), titles) {
            when (it) {

                0 -> {
                    val intent = Intent(requireActivity(), DB::class.java)
                    intent.putExtra("url", Env.userUrl)
                    intent.putExtra("title", "用户协议")
                    startActivity(intent)
                }

                1 -> {
                    val intent = Intent(requireActivity(), DB::class.java)
                    intent.putExtra(
                        "url",
                        Env.privateUrl
                    )
                    intent.putExtra("title", "隐私政策")
                    startActivity(intent)
                }

                2 -> startActivity(Intent(requireActivity(), AboutActivity::class.java))
            }
        }
        viewBinding.recyclerView.adapter = mAdapter
    }
}